<?php

include 'php/CouchDBFactory.php';

if (isset($_POST['action'])) {

		select();
    }

function select() {
	
	$jsonString = $_POST['action'];
	
	$couchdb = new CouchDB('ospf_simulator');
	$jsonId = $couchdb->getId($jsonString);
	
	$result = $couchdb->get_item($jsonId);
	try {
		if($couchdb->isDoc($result) || $couchdb->isDocEmpty($result))
		{
			$rev = $couchdb->getRev($result);
			$couchdb->delete($jsonId,$rev);	
		}
		$couchdb->create_doc($jsonId,$jsonString);
		
	} catch(CouchDBException $e) {
		die($e->errorMessage()."\n");
	}
    exit;
}

// Function for basic field validation (present and neither empty nor only white space
function IsNullOrEmptyString($question){
    return (!isset($question) || trim($question)==='');
}

?>